import { LresponseAuth } from '../modules/lresponse'
import ljwt from '../lib/ljwt'

export default async (ctx, next) => {
  const token = ctx.headers['access-token']
  if (!token && ctx.url != '/login') {
    ctx.body = new LresponseAuth().toJson()
    console.log(' -- error -- 未登录')
    return false
  } else {
    const userInfo = ljwt.verify(token)
    ctx.request['userInfo'] = userInfo
    await next()
  }
}
